<?php
/**
 * Krzysztof Zieliński 
 * Klasa do obsługi smsApi
 */
class smsApi
{
    private $username;
    private $password;
    private $from;
    
    public function __construct()
    {
        // Ustawienie zmiennych do smsApi
        $this -> username = "ziela1985";
        $this -> password = md5('ziela1234');
        $this -> from = "sos";
    }
    
    /**
     * Wysyłanie smsa
     * @return 
     * @param object $message - wiadomość  
     * @param object $to - nr komórkowy
     */
    public function sendSingleSms($message, $to)
    {                                                                                    
        global $g_oDB;
        $user = $this -> username;                             
        $pass = $this -> password;
        $from = $this -> from;
        
        $tempMessage = $message;
        $message = urlencode($message);
                                                                                                  
        $data = "?username=$user&password=$pass&encoding=utf-8&to=$to&message=$message&idx=123&eco=1";
        $file = fopen("http://api.smsapi.pl/send.do".$data,"r");
        $result = fread($file, 1024);
        fclose($file);
        $check = explode(":",$result);
        if($check[0] == "OK")
        {
            //$l_sQuery = "INSERT INTO sms_raports (sms_raport_msg_id,sms_raport_message,sms_raport_reciver_number) VALUES (?,?,?)";
//            $g_oDB -> PdoQuery($l_sQuery, array($check[1],$tempMessage,$to));
         $response = array();
         array_push($response, 'OK');
         array_push($response, $check[1]);
         array_push($response, $tempMessage);   
         return $response;
        }
        else
        {
            return $result;
        }
    }
    
    /**
     * Funkcja odpowiedzialna za pobranie ilości pozostałych punktów 
     * @return liczba punktów w serwisie smsApi
     */
    public function getCountOfPoints()
    {
        $user = $this -> username;
        $pass = $this -> password;
        
        $data = "?username=$user&password=$pass&points=1";
        $file = fopen("http://api.smsapi.pl/send.do".$data,"r");
        $result = fread($file, 1024);
        fclose($file);
        
        $points = explode(":",$result);
        echo trim($points[1]);exit;
        return trim($points[1]);exit;
    }
}
?> 